<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <meta name="apple-mobile-web-app-capable" content="yes" />

        <!-- Base Css Files -->
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/jqueryui/ui-lightness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/fontello/css/fontello.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/animate-css/animate.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/nifty-modal/css/component.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/magnific-popup/magnific-popup.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/css/style.css" rel="stylesheet" type="text/css" />
        <link href="__PUBLIC__/statics/coco-chat/assets/css/style-responsive.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/pace/pace.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/jquery-notifyjs/styles/metro/notify-metro.css" rel="stylesheet" type="text/css" />
		<link href="__PUBLIC__/statics/coco-chat/assets/libs/jquery-icheck/skins/all.css" rel="stylesheet" />
		<link href="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" type="text/css" />

		<!-- Extra CSS Files -->
      	<link href="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-validator/css/bootstrapValidator.min.css" rel="stylesheet"/>

        <!-- Custom Css Files -->
        <link href="__HOME_CSS__/style.css"  rel="stylesheet" />
    </head>
    <body>
	<!-- Begin page -->
	<div>
		<div class="sub-header-title">
			<h2>
				在线充值
			</h2>
		</div>
		<form role="form" id="pay-form" class="form-horizontal" action="{:U('Cash/pay')}" method="post">
			<input type="hidden" name="unit" value={$unit}>
		    <input type="hidden" name="order_no" value="{$order_no}">
			<div class="form-group">
				<label class="col-sm-2 control-label">会员编号</label>
				<div class="col-sm-5">
				  	<input type="text" class="form-control" readonly name="user_no" value="{$user['user_no']}">
				</div>
				<div class="col-sm-5">
					<p class="help-block">会员编号为当前登录账号，不能更改</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">真实姓名</label>
				<div class="col-sm-5">
				  	<input type="text" class="form-control" readonly name="name" value="{$user['realname']}">
				</div>
				<div class="col-sm-5">
					<p class="help-block">真实姓名为当前账号的真实姓名，不能更改</p>
				</div>
			</div>
			<div class="form-group" >
				<label class="col-sm-2 control-label">支付方式</label>
				<div class="col-sm-5">
					<div class="radio iradio">
						<if condition="is_mobile_request()">
							<label><input type="radio" name="pay_type"  value="alipay" checked>支付宝</label>
							<label><input type="radio" name="pay_type"  value="ipspay" disabled>环迅</label>
						<else />
							<label><input type="radio" name="pay_type"  value="alipay" <if condition="!$pay_type or $pay_type eq '0'">checked</if>>支付宝</label>
							<label><input type="radio" name="pay_type"  value="ipspay" <if condition="$pay_type eq '1'">checked</if>>环迅</label>
						</if>
					</div>
				</div>
				<div class="col-sm-5">
					<p class="help-block"></p>
				</div>
			</div>
			<div class="form-group">
				<label for="amount" class="col-sm-2 control-label"><span class="red_star">*</span>充值金额</label>
				<div class="col-sm-5">
				  	<input type="text" class="form-control" id="amount" name="amount" value="{$amount}" <if condition="!!$pay_type or $pay_type === '0'">readonly</if>>
				</div>
				<div class="col-sm-5">
					<p class="help-block">必须为(0,100000000)的两位小数或整数，并且是{$unit}的倍数,快捷支付必须大于2元</p>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-4 col-sm-4">
                    <button type="submit" class="btn btn-success">去充值</button>
                </div>
			</div>
		</form>
	</div>
	<!-- End of page -->

	<!-- Base Js Files -->
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery/jquery-1.11.1.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap/js/bootstrap.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jqueryui/jquery-ui-1.10.4.custom.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-ui-touch/jquery.ui.touch-punch.min.js"></script>
 	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-detectmobile/detect.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/fastclick/fastclick.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-slimscroll/jquery.slimscroll.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/nifty-modal/js/classie.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/nifty-modal/js/modalEffects.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-notifyjs/notify.min.js"></script>
    <script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-notifyjs/styles/metro/notify-metro.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/pace/pace.min.js"></script>

	<!-- Extra Js Files -->
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-validator/js/bootstrapValidator.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-icheck/icheck.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-select/bootstrap-select.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-select2/select2.min.js"></script>

	<!-- Custom Js Files -->
	<script src="__PUBLIC_JS__/sha1.js"></script>
	<script src="__HOME_JS__/common.js"></script>

	<script>
	$(function(){
		//ICHECK
		$('input').iCheck({
			checkboxClass: 'icheckbox_square-blue',
			radioClass: 'iradio_square-blue',
			increaseArea: '20%' // optional
		});

		if (is_weixin()) {
			window.parent.layer.alert('温馨提示：微信中限制了其它链接，请从右上角浏览器中打开该页面！', {
				title: '微信提示',
				btn: ['我知道了'], //按钮
			});
		}

		$('#pay-form').bootstrapValidator({
	        message: '',
	        trigger: 'blur',
	        submitHandler: function(validator, form, submitButton) {
				$('#pay-form').bootstrapValidator('disableSubmitButtons', false);
        		// 用ajax提交表单
        		var flag = false;
        		$.ajax({
			        type : "post",
			        url : form.attr('action'),
			        data : form.serialize(),
			        dataType : 'json',
			        async : false,
			        success : function(response){
			          //根据请求相应状态提示通知
			       		if(response.status){
							//notify("success",response.message);
							flag = true;
						}else{
							//弹出提示
						    window.parent.layer.msg(response.message);
							notify("error",response.message);
						}
			        }
				});
				if(flag){
					$('#pay-form').bootstrapValidator('disableSubmitButtons', true);
					var order_no = '{$order_no}';
					window.open("{:U('Cash/thirdPay')}?amount="+$('#amount').val()+"&pay_type="+$('input:radio:checked').val()+(order_no?"&order_no="+order_no:""));
				}
	        },
	        fields: {
	            amount: {
	                validators: {
	                	notEmpty: {
	                    },
	                	callback: {
	    					callback:function(value, validator){
								var radio = $("input:radio[name='pay_type']:checked").val();
	    						var reg=/^([1-9][0-9]{0,7}|0)(\.[0-9]{1,2})?$/;
	    						var unit = $('#pay-form').find("input[name='unit']").val();
	    						if(reg.test(value) && value>0){
	    							if((value*100) % (unit*100) == 0) return true;
	    						}
	    						return false;
	    					}
	    				}
	                }
	            }
	        }
	    });
	});

	function is_weixin(){
	    var ua = navigator.userAgent.toLowerCase();
	    if(ua.match(/MicroMessenger/i)=="micromessenger") {
	        return true;
	    } else {
	        return false;
	    }
	}
	</script>
	</body>
</html>